package com.ysd.controller;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ysd.entity.Admin;
import com.ysd.service.AdminService;
import com.ysd.util.Result;

@Controller
public class AdminController {
	   @Autowired
	   private AdminService adminService;
	
	   @RequestMapping("adminlogin")
	   @ResponseBody
       public Object AdminLogin(String name,String password,Admin admin,HttpSession session) {
	     Admin a=adminService.findAdmin(admin);
	     System.out.println(a);
	     if (a!= null) {
				if (a.getPassword().equals(password)) {
					session.setAttribute("admin", a);
					return Result.toClient("0", "登录成功", null, a);// 登录成功
					
				} else {
					return Result.toClient("1", "账号或密码错误！", null, null);// 密码错误
				}
			} else {// 没有查到
				return Result.toClient("1", "账号或密码错误！", null, null);
			}
	}	
	   /**
	   * 退出
	   */
	   @RequestMapping("/logout")
	   public void logout(HttpSession session){
	   //清除session
	   session.removeAttribute("admin");	
	   }
}

